import toolMgr from '@/biz/base/tool.js'
import dt from '@dt/dt'
import ruleOpt from '@/biz/option/rule.js'

let _this = null


function accessory(info) {
  console.log(info, 'infoaaaaaaaaaaa');
  let api = toolMgr.unloadFile()
  let files = []
  if (info.accessoryBOList && info.accessoryBOList.length > 0) {
    info.accessoryBOList.forEach(item => {
      if (item) {
        files.push({
          name: item.accessoryName,
          url: item.accessoryUrl
        })
      }
    })
  }
  return [{
    title: '附件上传',
    key: 'accessoryBOList',
    upload: {
      title: '附件上传',
      api,
      files,
      multiple: true,
      preview: (file) => {
        console.log(file, 'filefilefilefilefilefilefilefilefilefilefilefile');
        toolMgr.downloadFile(file.url, file.name)
      }
    },
    data: {
      to: (v) => {
        let accessoryBOList = v.map(item => {
          return {
            accessoryName: item.name,
            accessoryUrl: item.response ? item.response.data.imageURL : item.url
          }
        })
        return {
          accessoryBOList
        }
      }
    },
    rules: [{
      required: true,
      message: '请上传附件',
      type: 'array',
      trigger: 'blur'
    }]
  }]
}

function options(vm) {
  _this = vm
  return [
    [{
      title: '发放月份',
      key: 'bonusMonth',
      text: {}
    }],
    [{
      title: '在销激励总额',
      key: 'headerMoney',
      text: {},
      data: {
        from: (info) => {
          return info.headerMoney + "元"
        }
      }
    }],


    [{
      key: 'oaNumber',
      title: 'OA文电编号',
      placeholder: '请输入oa文电编号',
      input: {
        // type: 'number'
        maxlength: 20,
        showWordLimit: true,

      },
      rules: [
        ruleOpt.required('请输入备注'),
        ruleOpt.max(20),
        //   {
        //   required: true,
        //   message: '请输入OA文电编号',
        //   trigger: 'blur'
        // }
      ]
    }],


    accessory(_this.info),
    // [{
    //   title: '备注',
    //   key: 'remark',
    //   disabled: _this.$route.name !== 'levelPointsEdit' ? true : false,
    //   input: {
    //     type: 'textarea',
    //     autosize: {
    //       minRows: 4
    //     }
    //   },
    //   rules: [
    //     ruleOpt.max(300)
    //   ]
    // }]

    [{
      title: '备注',
      key: 'remark',
      input: {
        type: 'textarea',
        showWordLimit: true,
        maxlength: 300,
        autosize: {
          minRows: 4
        }
      },

      rules: [
        ruleOpt.required('请输入备注'),
        ruleOpt.max(300),
        //   {
        //   required: true,
        //   message: '请输入备注',
        //   trigger: 'blur'
        // }

      ]
    }]


  ]
}

export default {
  options
}